$(function () {
    $("#jqGrid").Grid({
        url: '../remit/list',
        colModel: [{
            label: 'id', name: 'id', index: 'id', key: true, hidden: true
        }, {
            label: '转账人', name: 'sysName', index: 'sysName',align:'center', width: 70
        }, {
            label: '转账人手机号', name: 'sysMobile', index: 'sysMobile',align:'center', width: 70
        }, {
            label: '收款人', name: 'nideshopName', index: 'nideshopName',align:'center', width: 70
        },{
            label: '收款人手机号', name: 'nideshopMobile', index: 'nideshopMobile',align:'center', width: 70
        },{
            label: '购物劵金额', name: 'remitFee', index: 'remitFee', width: 50,align:'center'
        }, {
            label: '转账时间', name: 'applyTime', index: 'applyTime',align:'center', width: 70, formatter: function (value) {
                return transDate(value);
            }
        },{
            label: '购物劵类型', name: 'remitType', index: 'remitType', align:'center',width: 40, formatter: function (value) {
                return trRemitType(value);
            }
        }]
    });
    $("#jqGrids").Grid({
        url: '../remit/lists',
        colModel: [{
            label: 'id', name: 'id', index: 'id', key: true, hidden: true
        },{
            label: '收款人', name: 'nideshopName', index: 'nideshopName',align:'center', width: 70
        },{
            label: '收款人手机号', name: 'nideshopMobile', index: 'nideshopMobile',align:'center', width: 70
        },{
            label: '购物劵金额', name: 'remitFee', index: 'remitFee', width: 50,align:'center'
        },{
            label: '周期', name: 'cycle', index: 'cycle', width: 50,align:'center'
        }]
    });
    var newHeight = $(window).height()-130;
    $(".ui-jqgrid .ui-jqgrid-bdiv").css("cssText","height: "+newHeight+"px!important;");
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        q: {
            sysMobile: '',
            nideshopMobile:'',
            dateRange:'',
            beginTime:'',
            endTime:'',
            operation:'',
            period:'',
        },
        operations:[
            {id:1,name:'查询'},
            {id:2,name:'统计'}
        ],
        periods:[
            {id:1,name:'日'},
            //{id:2,name:'周'},
            //{id:3,name:'月'},
            //{id:4,name:'季'},
            {id:5,name:'年'},
            {id:6,name:'全部'},
        ]
    },
    mounted(){
    },
    methods: {
        query: function () {
            if(vm.q.dateRange[0]){
                vm.q.beginTime = vm.dateFtt("yyyy-MM-dd hh:mm:ss",vm.q.dateRange[0]);
            }else{
                vm.q.beginTime = '';
            };
            if(vm.q.dateRange[1]){
                vm.q.endTime = vm.dateFtt("yyyy-MM-dd hh:mm:ss",vm.q.dateRange[1]);
            }else{
                vm.q.endTime = '';
            };
            console.log("q",vm.q)
            vm.reload();
        },
        statistics: function () {
            console.log("q",vm.q);
            vm.reload2();
        },
        reload: function (event) {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData: {
                    'sysMobile': vm.q.sysMobile,
                    'nideshopMobile': vm.q.nideshopMobile,
                    'beginTime':vm.q.beginTime,
                    'endTime':vm.q.endTime,
                },
                page: page,
            }).trigger("reloadGrid");
        },
        reload2: function (event) {
            vm.showList = true;
            var page = $("#jqGrids").jqGrid('getGridParam', 'page');
            $("#jqGrids").jqGrid('setGridParam',{
                postData: {
                    'nideshopMobile': vm.q.nideshopMobile,
                    'period':vm.q.period,
                },
                page: page,
            }).trigger("reloadGrid");
        },
        dateFtt:function(fmt,date){
            var o = {
                "M+" : date.getMonth()+1,                 //月份
                "d+" : date.getDate(),                    //日
                "h+" : date.getHours(),                   //小时
                "m+" : date.getMinutes(),                 //分
                "s+" : date.getSeconds(),                 //秒
                "q+" : Math.floor((date.getMonth()+3)/3), //季度
                "S"  : date.getMilliseconds()             //毫秒
            };
            if(/(y+)/.test(fmt))
                fmt=fmt.replace(RegExp.$1, (date.getFullYear()+"").substr(4 - RegExp.$1.length));
            for(var k in o)
                if(new RegExp("("+ k +")").test(fmt))
                    fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
            return fmt;
        },
    }
});
